<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注册绑定微信 - 记账助手</title>
    <link rel="stylesheet" href="styles.css">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body>
    <div class="screen">
        <div class="app-container">
            <div class="auth-container">
                <div class="auth-logo">💰</div>
                <h1 class="auth-title">注册并绑定微信</h1>
                
                <!-- 微信用户信息展示 -->
                <div class="wechat-user-info">
                    <div class="wechat-avatar">
                        <img id="wechat-avatar" src="" alt="微信头像">
                    </div>
                    <div class="wechat-nickname" id="wechat-nickname">微信用户</div>
                    <div class="bind-tip">注册完成后将自动绑定此微信账号</div>
                </div>
                
                <!-- 注册表单 -->
                <form class="auth-form" id="register-form">
                    <div class="form-group">
                        <label class="form-label" for="username">用户名</label>
                        <input type="text" id="username" class="form-input" placeholder="请设置用户名" required>
                    </div>
                    
                    <div class="form-group">
                        <label class="form-label" for="password">密码</label>
                        <input type="password" id="password" class="form-input" placeholder="请设置密码" required>
                    </div>
                    
                    <div class="form-group">
                        <label class="form-label" for="confirm-password">确认密码</label>
                        <input type="password" id="confirm-password" class="form-input" placeholder="请再次输入密码" required>
                    </div>
                    
                    <button type="submit" class="btn btn-primary">注册并绑定微信</button>
                </form>
                
                <div class="auth-footer">
                    <a href="wechat-bind.html" class="auth-link">返回上一步</a> |
                    <a href="wechat-login-bind.html" class="auth-link">已有账号登录</a>
                </div>
            </div>
        </div>
    </div>

    <script>
        // 页面加载时获取微信用户信息
        document.addEventListener('DOMContentLoaded', function() {
            const wechatUserInfo = sessionStorage.getItem('wechatUserInfo');
            if (wechatUserInfo) {
                const userInfo = JSON.parse(wechatUserInfo);
                document.getElementById('wechat-avatar').src = userInfo.avatar;
                document.getElementById('wechat-nickname').textContent = userInfo.nickname;
            } else {
                // 如果没有微信用户信息，返回登录页面
                window.location.href = 'login.html';
            }
        });
        
        // 注册表单提交
        document.getElementById('register-form').addEventListener('submit', function(e) {
            e.preventDefault();
            const username = document.getElementById('username').value;
            const password = document.getElementById('password').value;
            const confirmPassword = document.getElementById('confirm-password').value;
            
            // 验证密码是否一致
            if (password !== confirmPassword) {
                showAlert('两次输入的密码不一致，请重新输入');
                return;
            }
            
            // 这里应该是实际的注册逻辑，现在只是模拟
            if (username && password) {
                // 模拟注册成功并绑定微信
                showAlert('注册成功！微信账号绑定完成，即将跳转到首页...');
                setTimeout(() => {
                    // 清除微信用户信息
                    sessionStorage.removeItem('wechatUserInfo');
                    // 跳转到首页
                    window.location.href = 'index.html';
                }, 2000);
            } else {
                showAlert('请填写完整的注册信息');
            }
        });
        
        // Bootstrap 模态框函数
        function showAlert(message) {
            document.getElementById('alertModalBody').textContent = message;
            const alertModal = new bootstrap.Modal(document.getElementById('alertModal'));
            alertModal.show();
        }
    </script>

    <!-- Bootstrap 模态框 -->
    <div class="modal fade" id="alertModal" tabindex="-1" aria-labelledby="alertModalLabel" aria-hidden="true">
        <div class="modal-dialog modal-dialog-centered">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="alertModalLabel">提示</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body" id="alertModalBody">
                    <!-- 动态内容 -->
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-primary" data-bs-dismiss="modal">确定</button>
                </div>
            </div>
        </div>
    </div>

    <style>
        .wechat-user-info {
            text-align: center;
            margin-bottom: 30px;
            padding: 20px;
            background: white;
            border-radius: 16px;
            box-shadow: 0 4px 20px rgba(0,0,0,0.08);
        }
        
        .wechat-avatar {
            width: 60px;
            height: 60px;
            margin: 0 auto 10px;
            border-radius: 50%;
            overflow: hidden;
            border: 2px solid #07C160;
        }
        
        .wechat-avatar img {
            width: 100%;
            height: 100%;
            object-fit: cover;
        }
        
        .wechat-nickname {
            font-size: 16px;
            font-weight: 600;
            color: #2d3748;
            margin-bottom: 5px;
        }
        
        .bind-tip {
            font-size: 12px;
            color: #07C160;
            font-weight: 500;
        }
    </style>
</body>
</html>